package com.zcl.adapter;

import java.util.List;

import com.zcl.bean.UserInfo;
import com.zcl.iweibo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class UserInfoAdapter extends BaseAdapter {

	private Context mContext;
	private List<UserInfo> mUsers;
	public UserInfoAdapter(Context context, List<UserInfo> users) {
		mContext = context;
		mUsers = users;
	}

	@Override
	public int getCount() {
		return mUsers == null? 0 :mUsers.size();
	}

	@Override
	public Object getItem(int position) {
		return mUsers == null? null: mUsers.get(position);
	}

	@Override
	public long getItemId(int position) {
		return mUsers.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			v = LayoutInflater.from(mContext).inflate(R.layout.user_select_item, null);
			TextView name = (TextView) v.findViewById(R.id.text_user_name);		
			name.setText(mUsers.get(position).getUserName());
			ImageView head = (ImageView)v.findViewById(R.id.img_user_head);
			if(mUsers.get(position).getUserIcon()!=null){
				head.setImageDrawable(mUsers.get(position).getUserIcon());
			}
			
			
		}
		return v;
	}

}
